Ext.define('js.report.reportShowdowPage', {
    extend: 'Ext.grid.Panel',
    id:'reportShowdowPage',
    requires: ['js.Util', 'js.ctrl.Common',],
    controller: 'Common',
    autoScroll : true,
    margin:'20 30 30 30',
    height:600,
    bodyStyle: {
        backgroundColor: '#eee',
    },
    initComponent: function () {
        this.store = Ext.create('js.store.report.reportShowDowStore');
        this.store.getProxy().setExtraParam('pageNum', 1);
        this.store.load({
            callback:function () {
                let me = Ext.getCmp('reportShowdowPage');
                if(me){
                    if(me.store.data.items.length>0){
                        new Page({
                            id: 'paginationDowABC',
                            pageTotal: me.store.data.items[0].data.pageTotal, //必填,总页数
                            pageAmount: 10,  //每页多少条
                            dataTotal: me.store.data.items[0].data.dataTotal, //总共多少条数据
                            curPage:parseInt(me.store.data.items[0].data.pageNum), //初始页码,不填默认为1
                            pageSize: 5, //分页个数,不填默认为5
                            showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                            showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                            getPage: function (page) {
                                //获取当前页数
                                me.store.getProxy().setExtraParam('pageNum', page);
                                me.store.reload();
                            }
                        })
                    }else{
                        new Page({
                            id: 'paginationDowABC',
                            pageTotal: 1, //必填,总页数
                            pageAmount: 10,  //每页多少条
                            dataTotal: 0, //总共多少条数据
                            pageSize: 5, //分页个数,不填默认为5
                            showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                            showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                            getPage: function (page) {
                                //获取当前页数
                                me.store.getProxy().setExtraParam('pageNum', page);
                                me.store.reload();
                            }
                        })
                    }
                }
            }
        });
        this.columns = [
            {text: '工程名称', dataIndex: 'engineering_name', align: 'center',width:200},
            {text: '结构类型', dataIndex: 'structure_name', align: 'center', width:200,},
            {text: '地上</br>层数', dataIndex: 'aboveGround_floor', align: 'center',width:100,},
            {text: '地下</br>层数', dataIndex: 'underGround_floor', align: 'center', width:100},
            {text: '面积(㎡)', dataIndex: 'engineering_area', align: 'center', width:100,},
            {text: '建设单位名称', dataIndex: 'construction_unit_employer_name', align: 'center', width:300,},
            {text: '监理单位名称', dataIndex: 'drawing_unit_name', align: 'center', width:300,},
            {text: '勘察单位名称', dataIndex: 'survey_unit_name', align: 'center', width:300,},
            {text: '设计单位名称', dataIndex: 'construction_unit_contractor_name', align: 'center', width:300,},
            {text: '施工单位名称', dataIndex: 'supervisory_unit_name', align: 'center', width:300},
            {text: '图审单位名称', dataIndex: 'design_unit_name', align: 'center',width:300,},
            {text: '工程地址', dataIndex: 'engineering_address', align: 'center',width:200},
            {text: '状态', dataIndex: 'status', align: 'center',width:200},
        ];
        this.dockedItems = [
            {
                dock: 'top',
                xtype: 'toolbar',
                border:'none',
                margin:'0 0 20 0',
                items: [
                    {
                        xtype: 'datefield',
                        name: 'start_time',
                        emptyText: '年度',
                        fieldLabel: '年度:',
                        labelWidth: 60,
                        margin:'0 20% 10 0%',
                        id:'nd',
                        triggerAction: 'all',
                        labelSeparator: '',
                        width:'25%',
                        height: 30,
                        editable:false,
                        listeners: {
                            change: function (com, newValue, oldValue, eOpts) {//企业ID
                                let me = Ext.getCmp('reportShowdowPage');
                                me.store.getProxy().setExtraParam('nd', newValue);
                                me.store.reload();
                            }
                        }
                    },{
                        xtype: 'combobox',
                        emptyText: '建筑用途',
                        fieldLabel: '建筑用途:',
                        triggerAction: 'all',
                        height: 30,
                        width: '30%',
                        margin:'0 20% 10 29%',
                        labelSeparator: '',
                        editable: false,
                        displayField: 'dataType',
                        valueField: 'value',
                        id:'jzyt',
                        store:  Ext.create('js.store.wide.projectConstructionApplications',{
                            proxy: {
                                extraParams: {
                                    type: 0,
                                },
                            }
                        }),
                        listeners: {
                            change: function (com, newValue, oldValue, eOpts) {//企业ID
                                let me = Ext.getCmp('reportShowdowPage');
                                me.store.getProxy().setExtraParam('jzyt', newValue);
                                me.store.reload();
                            }
                        }
                    }, {
                        xtype: 'combobox',
                        emptyText: '区域',
                        fieldLabel: '区域:',
                        triggerAction: 'all',
                        id:'qy',
                        labelWidth: 60,
                        height: 30,
                        width: '25%',
                        margin:'0 58% 10 29%',
                        labelSeparator: '',
                        editable: false,
                        displayField: 'dataType',
                        valueField: 'value',
                        store:  Ext.create('js.store.wide.projectRegin',{
                            proxy: {
                                extraParams: {
                                    type: 0,
                                },
                            }
                        }),
                        listeners: {
                            change: function (com, newValue, oldValue, eOpts) {//企业ID
                                let me = Ext.getCmp('reportShowdowPage');
                                me.store.getProxy().setExtraParam('qy', newValue);
                                me.store.reload();
                            }
                        }
                    },{
                        xtype: 'button',
                        scala: 'medium',
                        cls:'button-Intelligent-sensor',
                        text: '刷新',
                        margin:'0 20% 10 0%',
                        width: '10%',
                        height:32,
                        handler: this.refresh,
                        scope: this,
                        toOpera: 0
                    },{
                        xtype: 'button',
                        scala: 'medium',
                        cls:'button-Intelligent-sensor',
                        text: '生成报表',
                      /*  margin:'0 100% 10 0%',*/
                        width: '10%',
                        height:32,
                        handler: this.scbb,
                        scope: this,
                        toOpera: 0
                    }

                ]
            },{
                xtype: 'panel',
                html:'<div id="paginationDowABC" class="pagination"></div>',
                dock: 'bottom',
                height:50,
                margin:'0 0 0 0',
                displayInfo: true,
            }]
        this.callParent(arguments);
    },scbb:function(){
        let nd=Ext.getCmp('nd').value;
        let jzyt=Ext.getCmp('jzyt').value;
        let jzytName=Ext.getCmp('jzyt').rawValue;
        let qy=Ext.getCmp('qy').value;
        let qyName=Ext.getCmp('qy').rawValue;
        let panel =Ext.getCmp('reportShowdowPage')
        panel.mask('正在加载数据请稍后');
        util.post('/toExcelRoutes', {
            action_type: 'reportExcelExport',
            nd:nd,
            jzytName:jzytName,
            qyName:qyName,
            qy:qy,
            jzyt:jzyt
        }).then(function (response) {
            panel.unmask();
            let obj = Ext.decode(response.responseText);
            if (obj.success) {
                let download  = setTimeout(function () {
                    location.href = "uploadExcelRouters?fileName=" + obj.fileName;
                    clearTimeout(download)
                },3000);
                Ext.toast('生成成功');
            } else {
                Ext.toast(`保存失败,${obj.message}`);
            }
        });
    },
    refresh: function (btn) {
        Ext.getCmp('nd').setValue('');
        Ext.getCmp('jzyt').setValue('');
        Ext.getCmp('qy').setValue('');
        this.getStore().reload();
    }
});